<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var intersection = function (nums1, nums2) {
        let map = new Map();
        // 第一次遍历
        for (let i = 0; i < nums1.length; i++) {
          if (map.has(nums1[i])) {
            let result = map.get(nums1[i]);
            result++;
            map.set(nums1[i], result);
          } else {
            map.set(nums1[i], 1);
          }
        }
        // 第二次遍历，查到相同的就赋值为 0
        for (let i = 0; i < nums2.length; i++) {
          if (map.has(nums2[i])) {
            map.set(nums2[i], 0);
          }
        }
        // 遍历 map
        let arr = [];
        for (let entry of map) {
          console.log(entry);
          if (entry[1] == 0) {
            arr.push(entry[0])
          }
        }
        
        // console.log('arr', arr);
        return arr;
      };

      intersection([1, 2, 3], [2, 3]);
    </script>
  </body>
</html>
